package com.nbjtjc.safe.service.edu;


import cn.afterturn.easypoi.excel.ExcelExportUtil;
import cn.afterturn.easypoi.excel.entity.TemplateExportParams;
import cn.hutool.core.collection.CollectionUtil;
import cn.hutool.core.util.ObjectUtil;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.nbjtjc.safe.bean.Page;
import com.nbjtjc.safe.bean.Result;
import com.nbjtjc.safe.mapper.edu.EduCertificateIssueDeptMapper;
import com.nbjtjc.safe.mapper.edu.EduCertificateMapper;
import com.nbjtjc.safe.mapper.edu.EduCertificateRetrainMapper;
import com.nbjtjc.safe.mapper.edu.EduCertificateTypeMapper;
import com.nbjtjc.safe.mapper.sys.SysDeptMapper;
import com.nbjtjc.safe.mapper.sys.SysUserMapper;
import com.nbjtjc.safe.model.edu.EduCertificate;
import com.nbjtjc.safe.model.edu.EduCertificateIssueDept;
import com.nbjtjc.safe.model.edu.EduCertificateRetrain;
import com.nbjtjc.safe.model.edu.EduCertificateType;
import com.nbjtjc.safe.model.sys.SysUser;
import com.nbjtjc.safe.util.FileUtil;
import com.nbjtjc.safe.util.MyShiroUtils;
import org.apache.poi.hssf.usermodel.HSSFCell;
import org.apache.poi.hssf.usermodel.HSSFRow;
import org.apache.poi.hssf.usermodel.HSSFSheet;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.poi.ss.usermodel.Workbook;
import org.apache.poi.xssf.usermodel.XSSFCell;
import org.apache.poi.xssf.usermodel.XSSFRow;
import org.apache.poi.xssf.usermodel.XSSFSheet;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpServletResponse;
import java.io.*;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.*;

@Service
public class EduCertificateService {
	@Autowired
    private EduCertificateMapper eduCertificateMapper;
    @Autowired
    private EduCertificateRetrainMapper eduCertificateRetrainMapper;
	@Autowired
	EduCertificateTypeMapper eduCertificateTypeMapper;
	@Autowired
	EduCertificateIssueDeptMapper eduCertificateIssueDeptMapper;
    @Autowired
    private SysDeptMapper sysDeptMapper;
    @Autowired
    private FileUtil fileUtil;
    @Value("${file.path.tempPath}")
    private String fileTempPath;
    @Autowired
    private SysUserMapper sysUserMapper;
    
    @Transactional(rollbackFor = {Throwable.class})
    public Result add(EduCertificate eduCertificate){
        Result result=new Result();
        if(ObjectUtil.isNull(eduCertificate)
                ){
            result.setFalse("持证培训为空");
            return result;
        }
        //无主键或主键原表不存在则新建，插入数据
        if(ObjectUtil.isNull(eduCertificate.getId())|| ObjectUtil.isNull(eduCertificateMapper.selectByPrimaryKey(eduCertificate.getId()))){
        	//证书名称有，ID没有的时候，在证书类型表中插入该证书，并获得ID给eduCertificate
        	if(ObjectUtil.isNotNull(eduCertificate.getCertificateName())&&ObjectUtil.isNull(eduCertificate.getCertificateTypeId())){
    			EduCertificateType certificateType = new EduCertificateType();
    			certificateType.setCertName(eduCertificate.getCertificateName());
    			List<EduCertificateType> certificateTypes = eduCertificateTypeMapper.findByName(certificateType);
    			if(CollectionUtil.isEmpty(certificateTypes)){
    				eduCertificateTypeMapper.insertSelective(certificateType);
    				eduCertificate.setCertificateTypeId(certificateType.getId());
    			}else if(certificateTypes.size()>1){
    	            result.setFalse("该证书名称有多个不同证书类型记录，请检查");
    	            return result;
    			}else{
    				certificateType = certificateTypes.get(0);
    				eduCertificate.setCertificateTypeId(certificateType.getId());
    			}
        	}
        	
        	//发证单位名称有，ID没有的时候，在发证单位表中插入该发证单位，并获得ID给eduCertificate
        	if(ObjectUtil.isNotNull(eduCertificate.getIssuingDepartment())&&ObjectUtil.isNull(eduCertificate.getIssuingDepartmentId())){
        		EduCertificateIssueDept certificateIssueDept = new EduCertificateIssueDept();
        		certificateIssueDept.setDeptName(eduCertificate.getIssuingDepartment());
    			List<EduCertificateIssueDept> certificateIssueDepts = eduCertificateIssueDeptMapper.findByName(certificateIssueDept);
    			if(CollectionUtil.isEmpty(certificateIssueDepts)){
    				eduCertificateIssueDeptMapper.insertSelective(certificateIssueDept);
    				eduCertificate.setIssuingDepartmentId(certificateIssueDept.getId());
    			}else if(certificateIssueDepts.size()>1){
    	            result.setFalse("该发证单位名称有多个不同发证单位记录，请检查");
    	            return result;
    			}else{
    				certificateIssueDept = certificateIssueDepts.get(0);
    				eduCertificate.setIssuingDepartmentId(certificateIssueDept.getId());
    			}
        	}
        	int  companeyId= MyShiroUtils.getCompanyId();
        	eduCertificate.setCompanyId(companeyId);
        	eduCertificate.setCompanyName(sysDeptMapper.findNameById(companeyId));
        	eduCertificate.setCreateDate(new Date());
        	eduCertificate.setCreateId(MyShiroUtils.getSessionUserId());
        	int res=eduCertificateMapper.insertSelective(eduCertificate);
        	if(res==0){
	            result.setFalse("插入失败");
	            return result;
	        }
        	//为方便测试不用每次输复训记录，复训记录为空时不改变复训记录表        	
//        	if(CollectionUtil.isNotEmpty(eduCertificate.getEduCertificateRetrains())){
        		result = insertEduCertificateRetrain(eduCertificate);
    	        if(result.isSuccess()==false){
    	            return result;
    	        }
        		
//        	}
        }else
        {
        	eduCertificate.setModifyDate(new Date());
        	eduCertificate.setModifyId(MyShiroUtils.getSessionUserId());
	        int res=eduCertificateMapper.updateByPrimaryKeySelective(eduCertificate);
	        if(res==0){
	            result.setFalse("更新失败");
		        return result;
	        }
	          //删除旧复训记录，插入新复训记录
        	//为方便测试不用每次输复训记录，复训记录为空时不改变复训记录表        	
//        	if(CollectionUtil.isNotEmpty(eduCertificate.getEduCertificateRetrains())){
        		int t = eduCertificate.getId();

        		if(CollectionUtil.isNotEmpty(eduCertificateRetrainMapper.findByCertificateId(t))){
        			 res=  eduCertificateRetrainMapper.deleteByEduCertificateId(t);
 		  	        if(res==0){
		        	  result.setFalse("删除旧复训记录失败");
			          return result;
 		  	        }
        		}
            	if(CollectionUtil.isNotEmpty(eduCertificate.getEduCertificateRetrains())){

        		result = insertEduCertificateRetrain(eduCertificate);
    	        if(result.isSuccess()==false){
    	            return result;
    	        }
        	}
        }
        result.setData(eduCertificate);
        return result;
    }
    
    private Result insertEduCertificateRetrain(EduCertificate eduCertificate){
        Result result=new Result();
    	if(CollectionUtil.isEmpty(eduCertificate.getEduCertificateRetrains())){
//            result.setFalse("插入对象为空");
        	return result;
	    }else{
		//将retrain的EduCertificateId都设为当前eduCertificate的ID
			List<EduCertificateRetrain> retrains =  eduCertificate.getEduCertificateRetrains();
			for(EduCertificateRetrain retrain: retrains){
				retrain.setEduCertificateId(eduCertificate.getId());
			}
	    	int res=eduCertificateRetrainMapper.insertList(eduCertificate.getEduCertificateRetrains());
	    	if(res==0){
	            result.setFalse("插入失败");
	            return result;
	        }
	    }
    	//更新持证培训主表中复训日期字段，该字段变为@Transient字段，无需更新
//    	res= eduCertificateRetrainMapper.updateRetrain(eduCertificate.getId());
//    	if(res==0){
//            result.setFalse("持证培训复训日期更新失败");
//            return result;
//
//        }
        result.setData(eduCertificate.getEduCertificateRetrains());

    	return result;
    }
//    
//	res=eduRequirementSurveyItemMapper.updateByPrimaryKeySelective(eduRequirementSurveyItemMapper.countItemsByReqInvestId(eduRequirementSurveyItem.getReqInvestId());


    public Result delete(Integer id){
        Result result=new Result();
        if(ObjectUtil.isNull(id)){
            result.setFalse("删除对象不能为空");
            return result;
        }
        int res = eduCertificateMapper.deleteByPrimaryKey(id);
     	if(res==0){
            result.setFalse("删除对象失败");
            return result;
        }
        return result;
    }
//按条件查出列表
	public Result find(EduCertificate eduCertificate) {
		Result result = new Result();
		PageHelper.startPage(eduCertificate.getPageCurrent(), eduCertificate.getPageSize());
		eduCertificate.setCompanyId(MyShiroUtils.getCompanyId());
		List<EduCertificate> eduCertificates = eduCertificateMapper.search(eduCertificate);
		System.out.println(eduCertificate.getStartDate());
		result.setData(new PageInfo<>(eduCertificates));
		return result;
	}
	
	public Result findDetail(EduCertificate eduCertificate) {
		Result result = new Result();
		PageHelper.startPage(eduCertificate.getPageCurrent(), eduCertificate.getPageSize());
		eduCertificate.setCompanyId(MyShiroUtils.getCompanyId());

		List<EduCertificate> eduCertificates = eduCertificateMapper.searchDetail(eduCertificate);
		System.out.println(eduCertificate.getStartDate());
		result.setData(new PageInfo<>(eduCertificates));
		return result;
	}

	
	//选中一个持证培训查看
		public Result show(int id) {
			Result result = new Result();
			EduCertificate eduCertificate = eduCertificateMapper.show(id);

			result.setData(eduCertificate);
			return result;
		}
		
		public Result batchRetrain(EduCertificate eduCertificate){
			Result result = new Result();
			if(CollectionUtil.isEmpty(eduCertificate.getEduCertificateRetrains()) 
//					&& ObjectUtil.isNull(retrainDate)
					){
	            result.setFalse("传入参数不能为空");
	            return result;
			}
			int res=eduCertificateMapper.batchRetrain(eduCertificate);
	     	if(res==0){
	            result.setFalse("更新持证培训失败");
	            return result;
	        }
	     	result.setData(eduCertificate.getEduCertificateRetrains());
			return result;
		}
		
		
		//导入持证培训excel
	    @Transactional(rollbackFor = {Throwable.class})
	    public Result addBatch(MultipartFile multipartFile) throws IOException, ParseException {
	        Result result=new Result();

	    	String fileName=multipartFile.getOriginalFilename();
	        File targetFile=new File(fileUtil.getFilePath()+multipartFile.getOriginalFilename());
	        if(!targetFile.getParentFile().exists()){
	            targetFile.getParentFile().mkdirs();
	        }
	        multipartFile.transferTo(targetFile);
	        if(fileName.endsWith("xls")){
	            result = readXls(targetFile);
	        }else if(fileName.endsWith("xlsx")){
	        	result = readXlsx(targetFile);
	        }else{
	        	result.setFalse("传入文件不是excel表格，请检查");
	        	return result;
	        }
	        return result;
	    }
	    
	  //导入xls
	    public Result readXls(File excelFile) throws IOException, ParseException {
	    	Result result=new Result();
	    	

	        InputStream is = new FileInputStream(excelFile);
	        // HSSFWorkbook 标识整个excel
	        HSSFWorkbook hssfWorkbook = new HSSFWorkbook(is);

	        HSSFSheet hssfSheet = hssfWorkbook.getSheetAt(0);
	        List<EduCertificate> eduCertificates = new ArrayList();
	       
	        //获取excel表中数据
	        for (int rowNum = 2; rowNum <= hssfSheet.getLastRowNum(); rowNum++) {
	            // HSSFRow表示行
	            HSSFRow hssfRow = hssfSheet.getRow(rowNum);
	            if(ObjectUtil.isNull(hssfRow)){
	            	break;
	            }
	            if(ObjectUtil.isNull(hssfRow.getCell(0))){
	            	break;
	            }
	            String content1 = hssfRow.getCell(0).getStringCellValue();
	            if(ObjectUtil.isNull(content1)||content1==""){
	            	break;
	            }
	            EduCertificate eduCertificateT = new EduCertificate();

//	            int minColIx = hssfRow.getFirstCellNum();
	            int maxColIx = hssfRow.getLastCellNum();
	        	//身份证号,并查出用户user_id
	        	String idNumber=hssfRow.getCell(0).getStringCellValue().trim();
	        	SysUser  sysUser = new SysUser();
	        	sysUser.setIdNumber(idNumber);
	        	//按身份证号查库中对象
	            List<SysUser> userTemps = sysUserMapper.search(sysUser,new Page());
	            //结果为空或查出的用户ID为空则库中无此人，无法新增持证记录
	            if(CollectionUtil.isEmpty(userTemps)){
	            	break;
	            }else if(ObjectUtil.isNull(userTemps.get(0).getUserId())){
	            	break;
	            }else{
	            	//查出有效用户，则关联证书记录
	            	eduCertificateT.setUserId(userTemps.get(0).getUserId());
	            }
	        	
	            int certCount = 0;
	            //一条用户记录可能有多个证书，certCount查出证书数量
	            for(certCount =0;(17+certCount*7)<maxColIx; ){
	            	String content = "";
	            	//每份证书7个字段，从第17列开始，查下一个第7字段是否有内容，有说明证书数量+1
	            	//该列单元格不为空
	            	if(ObjectUtil.isNotNull(hssfRow.getCell(17+certCount*7))){
	            		content = hssfRow.getCell(17+certCount*7).getStringCellValue();
	            	}
	            	//该单元格内容不为空且字数大于1（考虑有的填\、无 之类的字符）
	            	if(ObjectUtil.isNotNull(content)&&content!=""&&content.length()>1){
	            		certCount++;
	            	}else{
	            		break;
	            	}
	            }

	            for(int certNum=0;certNum<certCount;certNum++){
		            EduCertificate eduCertificate = new EduCertificate();
		            eduCertificate.setUserId(eduCertificateT.getUserId());
		            //证书名称
		            String  eduCertificateName = "";
		            if(ObjectUtil.isNotNull(hssfRow.getCell(17+certNum*7))&&ObjectUtil.isNotNull(hssfRow.getCell(17+certNum*7).getStringCellValue())){
			            eduCertificateName = hssfRow.getCell(17+certNum*7).getStringCellValue();
		            }else{
		            	break;
		            }
//		            String   eduCertificateName = hssfRow.getCell(17+certNum*7).getStringCellValue();

		            eduCertificate.setCertificateName(eduCertificateName);

		            //同一用户不能有2个相同证书
		            if(ObjectUtil.isNotNull(eduCertificateName)&&eduCertificateName!=""){
			            if(CollectionUtil.isNotEmpty(eduCertificateMapper.search(eduCertificate))){
			            	break;
			            }
		            }

		            
		            //发证单位
		            String issuingDept ="";
		            if(ObjectUtil.isNotNull(hssfRow.getCell(18+certNum*7))){
			            issuingDept =hssfRow.getCell(18+certNum*7).getStringCellValue();
			            eduCertificate.setIssuingDepartment(issuingDept);
		            }

		            
		            //证书编号
		            if(ObjectUtil.isNotNull(hssfRow.getCell(19+certNum*7))){
			            eduCertificate.setCertificateId(hssfRow.getCell(19+certNum*7).getStringCellValue());
		            }

		            //取证时间
//		            String dateString1 = null;
//		            if(ObjectUtil.isNotNull(hssfRow.getCell(20+certNum*7))){
//			        	dateString1 = hssfRow.getCell(20+certNum*7).getStringCellValue().trim();
//		            }
//		        	if(ObjectUtil.isNotNull(dateString1)&&dateString1!=""){
//		        		eduCertificate.setGetDate(formateDate(dateString1));
//		        	}
		        	
		        	String dateString1 = "";
		        	if(ObjectUtil.isNotNull(hssfRow.getCell(20+certNum*7))){
//		        		if(hssfRow.getCell(20+certNum*7).getCellType()==HSSFCell.CELL_TYPE_NUMERIC){
//		        			if(ObjectUtil.isNotNull(hssfRow.getCell(20+certNum*7).getDateCellValue())){
//		        				eduCertificate.setGetDate(hssfRow.getCell(20+certNum*7).getDateCellValue());
//		        			}
//		        		}else if(hssfRow.getCell(20+certNum*7).getCellType()==HSSFCell.CELL_TYPE_STRING){
//		    				dateString1 = hssfRow.getCell(20+certNum*7).getStringCellValue();
//		        			if(ObjectUtil.isNotNull(dateString1)&&dateString1!=""&&dateString1.trim()!=""){
//		        				eduCertificate.setGetDate(formateDate(dateString1));
//		        			}
//		        		}
		        	}
		            
		        	//证书有效期
//		        	String dateString2 =null;
//		        	if(ObjectUtil.isNotNull(hssfRow.getCell(21+certNum*7))){
//			        	dateString2 = hssfRow.getCell(21+certNum*7).getStringCellValue().trim();
//		        	}
//		        	if(ObjectUtil.isNotNull(dateString2)&&dateString2!=""){
//		        		eduCertificate.setExpiryDate(formateDate(dateString2));
//		        	}
		        	
		        	String dateString2 = "";
		        	if(ObjectUtil.isNotNull(hssfRow.getCell(21+certNum*7))){
//		        		if(hssfRow.getCell(21+certNum*7).getCellType()==HSSFCell.CELL_TYPE_NUMERIC){
//		        			if(ObjectUtil.isNotNull(hssfRow.getCell(21+certNum*7).getDateCellValue())){
//		        				eduCertificate.setExpiryDate(hssfRow.getCell(21+certNum*7).getDateCellValue());
//		        			}
//		        		}else if(hssfRow.getCell(21+certNum*7).getCellType()==HSSFCell.CELL_TYPE_STRING){
//		    				dateString2 = hssfRow.getCell(21+certNum*7).getStringCellValue();
//		        			if(ObjectUtil.isNotNull(dateString2)&&dateString2!=""&&dateString2.trim()!=""){
//		        				eduCertificate.setExpiryDate(formateDate(dateString2));
//		        			}
//		        		}
		        	}
		        	
		        	//复训周期
		        	String string1 = "";
		        	
		        	if(ObjectUtil.isNotNull(hssfRow.getCell(22+certNum*7))){
//		        		if(hssfRow.getCell(22+certNum*7).getCellType()==HSSFCell.CELL_TYPE_NUMERIC){
//		        			Double retrainCycle=hssfRow.getCell(22+certNum*7).getNumericCellValue();
//		        			eduCertificate.setRetrainCycle(retrainCycle.intValue());
//		        		}else if(hssfRow.getCell(22+certNum*7).getCellType()==HSSFCell.CELL_TYPE_STRING){
//					        string1 =  hssfRow.getCell(22+certNum*7).getStringCellValue();
//
//				        	if(ObjectUtil.isNotNull(string1)&&string1.length()>0&&string1!=""&&string1.trim()!=""){
//				        		if(string1.equals("每年")){
//					        		eduCertificate.setRetrainCycle(1);
//					        	}else {
//					        		//判断字符串中是否为数字
//					        		int numFlag = 1;
//					        		for(int i=0;i<string1.length();i++){
//						        		if(string1.charAt(i)>'9'&&string1.charAt(i)<'0'){
//						        			numFlag=0;
//						        			break;
//						        		}
//					        		}
//					        		//是数字则可赋值
//					        		if(numFlag==1){
//					        			eduCertificate.setRetrainCycle(Integer.parseInt(string1));
//					        		}
//					        	}
//				        	}
//		        		}
		        	}
//		        	String string1 =  null;
//		        	if(ObjectUtil.isNotNull(hssfRow.getCell(22+certNum*7))){
//			        	string1 =  hssfRow.getCell(22+certNum*7).getStringCellValue();
//		        	}
//		        	if(ObjectUtil.isNotNull(string1)&&string1.length()>0&&string1!=""){
//		        		if(string1.equals("每年")){
//			        		eduCertificate.setRetrainCycle(1);
//			        	}else {
//			        		//判断字符串中是否为数字
//			        		int numFlag = 1;
//			        		for(int i=0;i<string1.length();i++){
//				        		if(string1.charAt(i)>'9'&&string1.charAt(i)<'0'){
//				        			numFlag=0;
//				        			break;
//				        		}
//			        		}
//			        		//是数字则可赋值
//			        		if(numFlag==1){
//			        			eduCertificate.setRetrainCycle(Integer.parseInt(string1));
//			        		}
//			        	}
//		        	}
		        
		        	//复训记录
		        	String dateString3 = "";
		        	if(ObjectUtil.isNotNull(hssfRow.getCell(23+certNum*7))){
//		        		if(hssfRow.getCell(23+certNum*7).getCellType()==HSSFCell.CELL_TYPE_NUMERIC){
//		        			if(ObjectUtil.isNotNull(hssfRow.getCell(23+certNum*7).getDateCellValue())){
//		        				eduCertificate.setRetrainDate(hssfRow.getCell(23+certNum*7).getDateCellValue());
//		        			}
//		        		}else if(hssfRow.getCell(23+certNum*7).getCellType()==HSSFCell.CELL_TYPE_STRING){
//		    				dateString3 = hssfRow.getCell(23+certNum*7).getStringCellValue();
//		        			if(ObjectUtil.isNotNull(dateString3)&&dateString3!=""&&dateString3.trim()!=""){
//		        				eduCertificate.setRetrainDate(formateDate(dateString3));
//		        			}
//		        		}
		        	}
//		        	String dateString3 = null;
//		        	if(ObjectUtil.isNotNull(hssfRow.getCell(23+certNum*7))){
//			        	dateString3 = hssfRow.getCell(23+certNum*7).getStringCellValue().trim();
//		        	}
//		        	if(ObjectUtil.isNotNull(dateString3)&&dateString3!=""){
//		        		eduCertificate.setRetrainDate(formateDate(dateString3));
//		        	}
		        	
		        	//创建时间和用户
		        	eduCertificate.setCreateDate(new Date());
		        	eduCertificate.setCreateId(MyShiroUtils.getSessionUser().getUserId());
		        	//公司ID和名称
		        	int comId = userTemps.get(0).getCompanyId();
		        	if(ObjectUtil.isNotNull(comId)){
		        		eduCertificate.setCompanyId(comId);
		        		eduCertificate.setCompanyName(hssfRow.getCell(6).getStringCellValue().trim());
		        	}
		        	//发证单位Id
		        	if(ObjectUtil.isNotNull(issuingDept)&&issuingDept!=""){
		        		EduCertificateIssueDept eduCertificateIssueDept = new EduCertificateIssueDept();
		        		eduCertificateIssueDept.setDeptName(issuingDept);
		        		List<EduCertificateIssueDept> eduCertificateIssueDepts = eduCertificateIssueDeptMapper.findByName(eduCertificateIssueDept);
		        		if(CollectionUtil.isNotEmpty(eduCertificateIssueDepts)&&eduCertificateIssueDepts.size()>0){
		        			eduCertificate.setIssuingDepartmentId(eduCertificateIssueDepts.get(0).getId());
		        		}
		        	}
		        	//证书类型eduCertificateName
		        	if(ObjectUtil.isNotNull(eduCertificateName)&&eduCertificateName!=""){
		        		EduCertificateType eduCertificateType = new EduCertificateType();
		        		eduCertificateType.setCertName(eduCertificateName);
		        		List<EduCertificateType> eduCertificateTypes = eduCertificateTypeMapper.findByName(eduCertificateType);
		        		if(CollectionUtil.isNotEmpty(eduCertificateTypes)&&eduCertificateTypes.size()>0){
		        			eduCertificate.setCertificateTypeId(eduCertificateTypes.get(0).getId());
		        		}
		        	}
		        	
		        	if(ObjectUtil.isNotNull(eduCertificate.getCertificateName())&&eduCertificate.getCertificateName()!=""){
			            eduCertificates.add(eduCertificate);
		        	}
	            }
	        }
	        
	        if(CollectionUtil.isNotEmpty(eduCertificates)){
		        int res = eduCertificateMapper.insertList(eduCertificates);
		        if(res == 0){
		        	result.setFalse("添加数据失败");
		            return result;
		        }
		        
		        //复训记录表
		        for(EduCertificate eduCertificate :eduCertificates){
		        	EduCertificateRetrain eduCertificateRetrain = new EduCertificateRetrain();
		        	if(ObjectUtil.isNotNull(eduCertificate.getId())){
		        		//持证培训主对象ID赋值给复训子对象
			        	eduCertificateRetrain.setEduCertificateId(eduCertificate.getId());
			        	if(ObjectUtil.isNotNull(eduCertificate.getRetrainDate())){
			        		//复训培训日期赋给复训子对象
			        		eduCertificateRetrain.setRetrainRecord(eduCertificate.getRetrainDate());
			        		//创建时间、用户名、用户ID
			        		eduCertificateRetrain.setCreateDate(new Date());
			        		eduCertificateRetrain.setCreateId(MyShiroUtils.getSessionUserId());
			        		eduCertificateRetrain.setCreateUser(MyShiroUtils.getSessionUserName());

			        		//入库
			        		eduCertificateRetrainMapper.insertSelective(eduCertificateRetrain);
			        	}
		        	}
		        }
	        }

	        
	        result.setData(eduCertificates);

	        return result;
	    }

	    //导入xlsx
	    public  Result readXlsx(File excelFile) throws IOException, ParseException {
	    	Result result=new Result();
	    	

	        InputStream is = new FileInputStream(excelFile);
	        // XSSFWorkbook 标识整个excel
	        XSSFWorkbook xssfWorkbook = new XSSFWorkbook(is);

	        XSSFSheet xssfSheet = xssfWorkbook.getSheetAt(0);
	        List<EduCertificate> eduCertificates = new ArrayList();
	       
	        //获取excel表中数据
	        for (int rowNum = 2; rowNum <= xssfSheet.getLastRowNum(); rowNum++) {
	            // XSSFRow表示行
	            XSSFRow xssfRow = xssfSheet.getRow(rowNum);
	            if(ObjectUtil.isNull(xssfRow)){
	            	break;
	            }
	            if(ObjectUtil.isNull(xssfRow.getCell(0))){
	            	break;
	            }
	            String content1 = xssfRow.getCell(0).getStringCellValue();
	            if(ObjectUtil.isNull(content1)||content1==""){
	            	break;
	            }
	            EduCertificate eduCertificateT = new EduCertificate();

//	            int minColIx = xssfRow.getFirstCellNum();
	            int maxColIx = xssfRow.getLastCellNum();
	        	//身份证号,并查出用户user_id
	        	String idNumber=xssfRow.getCell(0).getStringCellValue().trim();
	        	SysUser  sysUser = new SysUser();
	        	sysUser.setIdNumber(idNumber);
	        	//按身份证号查库中对象
	            List<SysUser> userTemps = sysUserMapper.search(sysUser,new Page());
	            //结果为空或查出的用户ID为空则库中无此人，无法新增持证记录
	            if(CollectionUtil.isEmpty(userTemps)){
	            	break;
	            }else if(ObjectUtil.isNull(userTemps.get(0).getUserId())){
	            	break;
	            }else{
	            	//查出有效用户，则关联证书记录
	            	eduCertificateT.setUserId(userTemps.get(0).getUserId());
	            }
	        	
	            int certCount = 0;
	            //一条用户记录可能有多个证书，certCount查出证书数量
	            for(certCount =0;(17+certCount*7)<maxColIx; ){
	            	String content = "";
	            	//每份证书7个字段，从第17列开始，查下一个第7字段是否有内容，有说明证书数量+1
	            	//该列单元格不为空
	            	if(ObjectUtil.isNotNull(xssfRow.getCell(17+certCount*7))){
	            		content = xssfRow.getCell(17+certCount*7).getStringCellValue();
	            	}
	            	//该单元格内容不为空且字数大于1（考虑有的填\、无 之类的字符）
	            	if(ObjectUtil.isNotNull(content)&&content!=""&&content.length()>1){
	            		certCount++;
	            	}else{
	            		break;
	            	}
	            }

	            for(int certNum=0;certNum<certCount;certNum++){
		            EduCertificate eduCertificate = new EduCertificate();
		            eduCertificate.setUserId(eduCertificateT.getUserId());
		            //证书名称
		            String  eduCertificateName = "";
		            if(ObjectUtil.isNotNull(xssfRow.getCell(17+certNum*7))&&ObjectUtil.isNotNull(xssfRow.getCell(17+certNum*7).getStringCellValue())){
			            eduCertificateName = xssfRow.getCell(17+certNum*7).getStringCellValue();
		            }else{
		            	break;
		            }
//		            String   eduCertificateName = xssfRow.getCell(17+certNum*7).getStringCellValue();

		            eduCertificate.setCertificateName(eduCertificateName);

		            //同一用户不能有2个相同证书
		            if(ObjectUtil.isNotNull(eduCertificateName)&&eduCertificateName!=""){
			            if(CollectionUtil.isNotEmpty(eduCertificateMapper.search(eduCertificate))){
			            	break;
			            }
		            }

		            
		            //发证单位
		            String issuingDept ="";
		            if(ObjectUtil.isNotNull(xssfRow.getCell(18+certNum*7))){
			            issuingDept =xssfRow.getCell(18+certNum*7).getStringCellValue();
			            eduCertificate.setIssuingDepartment(issuingDept);
		            }

		            
		            //证书编号
		            if(ObjectUtil.isNotNull(xssfRow.getCell(19+certNum*7))){
			            eduCertificate.setCertificateId(xssfRow.getCell(19+certNum*7).getStringCellValue());
		            }

		            //取证时间
//		            String dateString1 = null;
//		            if(ObjectUtil.isNotNull(xssfRow.getCell(20+certNum*7))){
//			        	dateString1 = xssfRow.getCell(20+certNum*7).getStringCellValue().trim();
//		            }
//		        	if(ObjectUtil.isNotNull(dateString1)&&dateString1!=""){
//		        		eduCertificate.setGetDate(formateDate(dateString1));
//		        	}
		        	
		        	String dateString1 = "";
		        	if(ObjectUtil.isNotNull(xssfRow.getCell(20+certNum*7))){
//		        		if(xssfRow.getCell(20+certNum*7).getCellType()==XSSFCell.CELL_TYPE_NUMERIC){
//		        			if(ObjectUtil.isNotNull(xssfRow.getCell(20+certNum*7).getDateCellValue())){
//		        				eduCertificate.setGetDate(xssfRow.getCell(20+certNum*7).getDateCellValue());
//		        			}
//		        		}else if(xssfRow.getCell(20+certNum*7).getCellType()==XSSFCell.CELL_TYPE_STRING){
//		    				dateString1 = xssfRow.getCell(20+certNum*7).getStringCellValue();
//		        			if(ObjectUtil.isNotNull(dateString1)&&dateString1!=""&&dateString1.trim()!=""){
//		        				eduCertificate.setGetDate(formateDate(dateString1));
//		        			}
//		        		}
		        	}
		            
		        	//证书有效期
//		        	String dateString2 =null;
//		        	if(ObjectUtil.isNotNull(xssfRow.getCell(21+certNum*7))){
//			        	dateString2 = xssfRow.getCell(21+certNum*7).getStringCellValue().trim();
//		        	}
//		        	if(ObjectUtil.isNotNull(dateString2)&&dateString2!=""){
//		        		eduCertificate.setExpiryDate(formateDate(dateString2));
//		        	}
		        	
		        	String dateString2 = "";
		        	if(ObjectUtil.isNotNull(xssfRow.getCell(21+certNum*7))){
//		        		if(xssfRow.getCell(21+certNum*7).getCellType()==XSSFCell.CELL_TYPE_NUMERIC){
//		        			if(ObjectUtil.isNotNull(xssfRow.getCell(21+certNum*7).getDateCellValue())){
//		        				eduCertificate.setExpiryDate(xssfRow.getCell(21+certNum*7).getDateCellValue());
//		        			}
//		        		}else if(xssfRow.getCell(21+certNum*7).getCellType()==XSSFCell.CELL_TYPE_STRING){
//		    				dateString2 = xssfRow.getCell(21+certNum*7).getStringCellValue();
//		        			if(ObjectUtil.isNotNull(dateString2)&&dateString2!=""&&dateString2.trim()!=""){
//		        				eduCertificate.setExpiryDate(formateDate(dateString2));
//		        			}
//		        		}
		        	}
		        	
		        	//复训周期
		        	String string1 = "";
		        	
		        	if(ObjectUtil.isNotNull(xssfRow.getCell(22+certNum*7))){
//		        		if(xssfRow.getCell(22+certNum*7).getCellType()==XSSFCell.CELL_TYPE_NUMERIC){
//		        			Double retrainCycle=xssfRow.getCell(22+certNum*7).getNumericCellValue();
//		        			eduCertificate.setRetrainCycle(retrainCycle.intValue());
//		        		}else if(xssfRow.getCell(22+certNum*7).getCellType()==XSSFCell.CELL_TYPE_STRING){
//					        string1 =  xssfRow.getCell(22+certNum*7).getStringCellValue();
//
//				        	if(ObjectUtil.isNotNull(string1)&&string1.length()>0&&string1!=""&&string1.trim()!=""){
//				        		if(string1.equals("每年")){
//					        		eduCertificate.setRetrainCycle(1);
//					        	}else {
//					        		//判断字符串中是否为数字
//					        		int numFlag = 1;
//					        		for(int i=0;i<string1.length();i++){
//						        		if(string1.charAt(i)>'9'&&string1.charAt(i)<'0'){
//						        			numFlag=0;
//						        			break;
//						        		}
//					        		}
//					        		//是数字则可赋值
//					        		if(numFlag==1){
//					        			eduCertificate.setRetrainCycle(Integer.parseInt(string1));
//					        		}
//					        	}
//				        	}
//		        		}
		        	}
//		        	String string1 =  null;
//		        	if(ObjectUtil.isNotNull(xssfRow.getCell(22+certNum*7))){
//			        	string1 =  xssfRow.getCell(22+certNum*7).getStringCellValue();
//		        	}
//		        	if(ObjectUtil.isNotNull(string1)&&string1.length()>0&&string1!=""){
//		        		if(string1.equals("每年")){
//			        		eduCertificate.setRetrainCycle(1);
//			        	}else {
//			        		//判断字符串中是否为数字
//			        		int numFlag = 1;
//			        		for(int i=0;i<string1.length();i++){
//				        		if(string1.charAt(i)>'9'&&string1.charAt(i)<'0'){
//				        			numFlag=0;
//				        			break;
//				        		}
//			        		}
//			        		//是数字则可赋值
//			        		if(numFlag==1){
//			        			eduCertificate.setRetrainCycle(Integer.parseInt(string1));
//			        		}
//			        	}
//		        	}
		        
		        	//复训记录
		        	String dateString3 = "";
		        	if(ObjectUtil.isNotNull(xssfRow.getCell(23+certNum*7))){
//		        		if(xssfRow.getCell(23+certNum*7).getCellType()==XSSFCell.CELL_TYPE_NUMERIC){
//		        			if(ObjectUtil.isNotNull(xssfRow.getCell(23+certNum*7).getDateCellValue())){
//		        				eduCertificate.setRetrainDate(xssfRow.getCell(23+certNum*7).getDateCellValue());
//		        			}
//		        		}else if(xssfRow.getCell(23+certNum*7).getCellType()==XSSFCell.CELL_TYPE_STRING){
//		    				dateString3 = xssfRow.getCell(23+certNum*7).getStringCellValue();
//		        			if(ObjectUtil.isNotNull(dateString3)&&dateString3!=""&&dateString3.trim()!=""){
//		        				eduCertificate.setRetrainDate(formateDate(dateString3));
//		        			}
//		        		}
		        	}
//		        	String dateString3 = null;
//		        	if(ObjectUtil.isNotNull(xssfRow.getCell(23+certNum*7))){
//			        	dateString3 = xssfRow.getCell(23+certNum*7).getStringCellValue().trim();
//		        	}
//		        	if(ObjectUtil.isNotNull(dateString3)&&dateString3!=""){
//		        		eduCertificate.setRetrainDate(formateDate(dateString3));
//		        	}
		        	
		        	//创建时间和用户
		        	eduCertificate.setCreateDate(new Date());
		        	eduCertificate.setCreateId(MyShiroUtils.getSessionUser().getUserId());
		        	//公司ID和名称
		        	int comId = userTemps.get(0).getCompanyId();
		        	if(ObjectUtil.isNotNull(comId)){
		        		eduCertificate.setCompanyId(comId);
		        		eduCertificate.setCompanyName(xssfRow.getCell(6).getStringCellValue().trim());
		        	}
		        	//发证单位Id
		        	if(ObjectUtil.isNotNull(issuingDept)&&issuingDept!=""){
		        		EduCertificateIssueDept eduCertificateIssueDept = new EduCertificateIssueDept();
		        		eduCertificateIssueDept.setDeptName(issuingDept);
		        		List<EduCertificateIssueDept> eduCertificateIssueDepts = eduCertificateIssueDeptMapper.findByName(eduCertificateIssueDept);
		        		if(CollectionUtil.isNotEmpty(eduCertificateIssueDepts)&&eduCertificateIssueDepts.size()>0){
		        			eduCertificate.setIssuingDepartmentId(eduCertificateIssueDepts.get(0).getId());
		        		}
		        	}
		        	//证书类型eduCertificateName
		        	if(ObjectUtil.isNotNull(eduCertificateName)&&eduCertificateName!=""){
		        		EduCertificateType eduCertificateType = new EduCertificateType();
		        		eduCertificateType.setCertName(eduCertificateName);
		        		List<EduCertificateType> eduCertificateTypes = eduCertificateTypeMapper.findByName(eduCertificateType);
		        		if(CollectionUtil.isNotEmpty(eduCertificateTypes)&&eduCertificateTypes.size()>0){
		        			eduCertificate.setCertificateTypeId(eduCertificateTypes.get(0).getId());
		        		}
		        	}
		        	
		        	if(ObjectUtil.isNotNull(eduCertificate.getCertificateName())&&eduCertificate.getCertificateName()!=""){
			            eduCertificates.add(eduCertificate);
		        	}
	            }
	        }
	        
	        if(CollectionUtil.isNotEmpty(eduCertificates)){
		        int res = eduCertificateMapper.insertList(eduCertificates);
		        if(res == 0){
		        	result.setFalse("添加数据失败");
		            return result;
		        }
		        
		        //复训记录表
		        for(EduCertificate eduCertificate :eduCertificates){
		        	EduCertificateRetrain eduCertificateRetrain = new EduCertificateRetrain();
		        	if(ObjectUtil.isNotNull(eduCertificate.getId())){
		        		//持证培训主对象ID赋值给复训子对象
			        	eduCertificateRetrain.setEduCertificateId(eduCertificate.getId());
			        	if(ObjectUtil.isNotNull(eduCertificate.getRetrainDate())){
			        		//复训培训日期赋给复训子对象
			        		eduCertificateRetrain.setRetrainRecord(eduCertificate.getRetrainDate());
			        		//创建时间、用户名、用户ID
			        		eduCertificateRetrain.setCreateDate(new Date());
			        		eduCertificateRetrain.setCreateId(MyShiroUtils.getSessionUserId());
			        		eduCertificateRetrain.setCreateUser(MyShiroUtils.getSessionUserName());

			        		//入库
			        		eduCertificateRetrainMapper.insertSelective(eduCertificateRetrain);
			        	}
		        	}
		        }
	        }

	        
	        result.setData(eduCertificates);

	        return result;
	    }
//	    //导入xlsx
//	    public  Result readXlsx(File excelFile) throws IOException, ParseException {
//	    	Result result=new Result();
//	    	
//
//	        InputStream is = new FileInputStream(excelFile);
//	        // XSSFWorkbook 标识整个excel
//	        XSSFWorkbook xssfWorkbook = new XSSFWorkbook(is);
//
//	        XSSFSheet xssfSheet = xssfWorkbook.getSheetAt(0);
//	        List<EduCertificate> eduCertificates = new ArrayList();
//	       
//	        //获取excel表中数据
//	        for (int rowNum = 2; rowNum <= xssfSheet.getLastRowNum(); rowNum++) {
//	            // XSSFRow表示行
//	            XSSFRow xssfRow = xssfSheet.getRow(rowNum);
//	            String content1 = xssfRow.getCell(0).getStringCellValue();
//	            if(ObjectUtil.isNull(content1)||content1==""){
//	            	break;
//	            }
//	            EduCertificate eduCertificate = new EduCertificate();
//
////	            int minColIx = xssfRow.getFirstCellNum();
////	            int maxColIx = xssfRow.getLastCellNum();
//	        	//身份证号,并查出用户user_id
//	        	String idNumber=xssfRow.getCell(0).getStringCellValue().trim();
//	        	SysUser  sysUser = new SysUser();
//	        	sysUser.setIdNumber(idNumber);
//	            List<SysUser> userTemps = sysUserMapper.search(sysUser,new Page());
//	            if(CollectionUtil.isEmpty(userTemps)){
//	            	break;
//	            }else if(ObjectUtil.isNull(userTemps.get(0).getUserId())){
//	            	break;
//	            }else{
//	            	eduCertificate.setUserId(userTemps.get(0).getUserId());
//	            }
//	        	
//	            //证书名称
//	            String  eduCertificateName = xssfRow.getCell(17).getStringCellValue().trim();
//	            eduCertificate.setCertificateName(eduCertificateName);
//	            //同一用户不能有2个相同证书
//	            if(ObjectUtil.isNotNull(eduCertificateName)&&eduCertificateName!=""){
//		            if(CollectionUtil.isNotEmpty(eduCertificateMapper.search(eduCertificate))){
//		            	break;
//		            }
//	            }
//
//	            
//	            //发证单位
//	            String issuingDept =xssfRow.getCell(18).getStringCellValue();
//	            eduCertificate.setIssuingDepartment(issuingDept);
//	            
//	            //证书编号
//	            eduCertificate.setCertificateId(xssfRow.getCell(19).getStringCellValue());
//
//	            //取证时间
//	        	String dateString1 = xssfRow.getCell(20).getStringCellValue().trim();
//	        	if(ObjectUtil.isNotNull(dateString1)&&dateString1!=""){
//	        		eduCertificate.setGetDate(formateDate(dateString1));
//	        	}
//	            
//	        	//证书有效期
//	        	String dateString2 = xssfRow.getCell(21).getStringCellValue().trim();
//	        	if(ObjectUtil.isNotNull(dateString2)&&dateString2!=""){
//	        		eduCertificate.setExpiryDate(formateDate(dateString2));
//	        	}
//	        	
//	        	//复训周期
//	        	String string1 =  xssfRow.getCell(22).getStringCellValue().trim();
//	        	if(ObjectUtil.isNotNull(string1)&&string1.length()>0&&string1!=""){
//	        		if(string1.equals("每年")){
//		        		eduCertificate.setRetrainCycle(1);
//		        	}else {
//		        		//判断字符串中是否为数字
//		        		int numFlag = 1;
//		        		for(int i=0;i<string1.length();i++){
//			        		if(string1.charAt(i)>'9'&&string1.charAt(i)<'0'){
//			        			numFlag=0;
//			        			break;
//			        		}
//		        		}
//		        		//是数字则可赋值
//		        		if(numFlag==1){
//		        			eduCertificate.setRetrainCycle(Integer.parseInt(string1));
//		        		}
//		        	}
//	        	}
//	        
//	        	//复训记录
//	        	String dateString3 = xssfRow.getCell(23).getStringCellValue().trim();
//	        	if(ObjectUtil.isNotNull(dateString3)&&dateString2!=""){
//	        		eduCertificate.setRetrainDate(formateDate(dateString3));
//	        	}
//	        	
//	        	//创建时间和用户
//	        	eduCertificate.setCreateDate(new Date());
//	        	eduCertificate.setCreateId(MyShiroUtils.getSessionUser().getUserId());
//	        	//公司ID和名称
//	        	int comId = userTemps.get(0).getCompanyId();
//	        	if(ObjectUtil.isNotNull(comId)){
//	        		eduCertificate.setCompanyId(comId);
//	        		eduCertificate.setCompanyName(xssfRow.getCell(6).getStringCellValue().trim());
//	        	}
//	        	//发证单位Id
//	        	if(ObjectUtil.isNotNull(issuingDept)&&issuingDept!=""){
//	        		EduCertificateIssueDept eduCertificateIssueDept = new EduCertificateIssueDept();
//	        		eduCertificateIssueDept.setDeptName(issuingDept);
//	        		List<EduCertificateIssueDept> eduCertificateIssueDepts = eduCertificateIssueDeptMapper.findByName(eduCertificateIssueDept);
//	        		if(CollectionUtil.isNotEmpty(eduCertificateIssueDepts)&&eduCertificateIssueDepts.size()>0){
//	        			eduCertificate.setIssuingDepartmentId(eduCertificateIssueDepts.get(0).getId());
//	        		}
//	        	}
//	        	//证书类型eduCertificateName
//	        	if(ObjectUtil.isNotNull(eduCertificateName)&&eduCertificateName!=""){
//	        		EduCertificateType eduCertificateType = new EduCertificateType();
//	        		eduCertificateType.setCertName(eduCertificateName);
//	        		List<EduCertificateType> eduCertificateTypes = eduCertificateTypeMapper.findByName(eduCertificateType);
//	        		if(CollectionUtil.isNotEmpty(eduCertificateTypes)&&eduCertificateTypes.size()>0){
//	        			eduCertificate.setCertificateTypeId(eduCertificateTypes.get(0).getId());
//	        		}
//	        	}
//	        	
//	        	if(ObjectUtil.isNotNull(eduCertificate.getCertificateName())&&eduCertificate.getCertificateName()!=""){
//		            eduCertificates.add(eduCertificate);
//	        	}
//	        }
//	        if(CollectionUtil.isNotEmpty(eduCertificates)){
//		        int res = eduCertificateMapper.insertList(eduCertificates);
//		        if(res == 0){
//		        	result.setFalse("添加数据失败");
//		            return result;
//		        }
//		        
//		        //复训记录表
//		        for(EduCertificate eduCertificate :eduCertificates){
//		        	EduCertificateRetrain eduCertificateRetrain = new EduCertificateRetrain();
//		        	if(ObjectUtil.isNotNull(eduCertificate.getId())){
//		        		//持证培训主对象ID赋值给复训子对象
//			        	eduCertificateRetrain.setEduCertificateId(eduCertificate.getId());
//			        	if(ObjectUtil.isNotNull(eduCertificate.getRetrainDate())){
//			        		//复训培训日期赋给复训子对象
//			        		eduCertificateRetrain.setRetrainRecord(eduCertificate.getRetrainDate());
//			        		//创建时间、用户名、用户ID
//			        		eduCertificateRetrain.setCreateDate(new Date());
//			        		eduCertificateRetrain.setCreateId(MyShiroUtils.getSessionUserId());
//			        		eduCertificateRetrain.setCreateUser(MyShiroUtils.getSessionUserName());
//
//			        		//入库
//			        		eduCertificateRetrainMapper.insertSelective(eduCertificateRetrain);
//			        	}
//		        	}
//		        }
//	        }
//
//	        
//	        result.setData(eduCertificates);
//
//	        return result;
//	    }
	    
	    //导出持证培训
	    public Result eduCertificateExcelOutput(HttpServletResponse response, EduCertificate eduCertificate) {
	    	Result result = new Result();

	    	try {
	            Map<String, Object> map = new HashMap<>();

	            
	            List<EduCertificate> eduCertificates = eduCertificateMapper.searchDetail(eduCertificate);
	            if (CollectionUtil.isEmpty(eduCertificates)) {
	            	return result;
	            }
	            int i=1;
	            for(EduCertificate eduCert:eduCertificates){
	            	eduCertificates.get(i-1).setNum(i);
	            	i++;
	            }
	            map.put("eduCts", eduCertificates);
	            TemplateExportParams params = new TemplateExportParams(
	                    "reportTemplates/edu/eduCertificateOutput.xlsx");
	            params.setHeadingStartRow(0);
	            params.setHeadingRows(1);

	            Workbook workbook = ExcelExportUtil.exportExcel(params, map);

//	            PoiMergeCellUtil.mergeCells(workbook.getSheetAt(0), 3, 0, 12);
	            File savefile = new File(fileTempPath);
	            if (!savefile.exists()) {
	                savefile.mkdirs();
	            }
	            String filePath = fileTempPath + "持证管理表-" + "-" + MyShiroUtils.getSessionUserId() + ".xlsx";
	            FileOutputStream fos = new FileOutputStream(filePath);
	            workbook.write(fos);
	            fos.close();
	            fileUtil.writeFile(response, new File(filePath));
	        } catch (IOException e) {
	            e.printStackTrace();
	        }
	    	return result;
	    }
	    
	    //将单元格中的日期字符串转为JAVA日期类型,支持2017/1/1，2017.1.1格式
	    Date formateDate(String dateString) throws ParseException{
	    	Date date =new Date();
	    	
	    	if(dateString.length()<6||dateString.length()>10){
	    		return null;
	    	}
	    	
			char separator=dateString.charAt(4);
			
	    	String format=null;

			int lastSepPlace = dateString.lastIndexOf(separator);
			if(lastSepPlace==4){
				//只有年月
				//月份是M还是MM
				if(dateString.charAt(5)=='0'){
					format =  "yyyy"+separator+"MM";
				}else{
					format = "yyyy"+separator+"M";
				}
			}else if(lastSepPlace>4 && lastSepPlace<8){
				//有年月日
				//月份是M还是MM
				if(dateString.charAt(5)=='0'){
					format =  "yyyy"+separator+"MM";
				}else{
					format = "yyyy"+separator+"M";
				}
				//日是d还是dd
				if(dateString.charAt(dateString.length()-2)=='0'){
					format = format+separator+"dd";
				}else{
					format = format+separator +"d";
				}
			}else{
				return null;
			}
	    	SimpleDateFormat sdf1 = new SimpleDateFormat(format);
			
			
	    	date = sdf1.parse(dateString);
	    	return date;
	    }
}
